home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / langs / iconv8_l.arc / IDOL.ARC / BUFFER.IOL < prev    next >
Encoding:
Text File  |  1990-03-19  |  3.4 KB  |  130 lines

  1.     class buffer(public filename,text,index)
  2.       # read a buffer in from a file
  3.       method read()
  4.         f := open(self.filename,"r") | fail
  5.         self$erase()
  6.         every put(self.text,!f)
  7.         close(f)
  8.         return
  9.       end
  10.       # write a buffer out to a file
  11.       method write()
  12.         f := open(self.filename,"w") | fail
  13.         every write(f,!self.text)
  14.         close(f)
  15.       end
  16.       # insert a line at the current index
  17.       method insert(s)
  18.         if self.index = 1 then {
  19.           push(self.text,s)
  20.         } else if self.index > *self.text then {
  21.           put(self.text,s)
  22.         } else {
  23.           self.text := self.text[1:self.index]|||[s]|||self.text[self.index:0]
  24.         }
  25.         self.index +:= 1
  26.         return
  27.       end
  28.       # delete a line at the current index
  29.       method delete()
  30.         if self.index > *self.text then fail
  31.         rv := self.text[self.index]
  32.     if self.index=1 then pull(self.text)
  33.     else if self.index = *self.text then pop(self.text)
  34.     else self.text := self.text[1:self.index]|||self.text[self.index+1:0]
  35.         return rv
  36.       end
  37.       # move the current index to an arbitrary line
  38.       method goto(l)
  39.         if (0 <= l) & (l <= self.index+1) then return self.index := l
  40.       end
  41.       # return the current line and advance the current index
  42.       method forward()
  43.         if self.index > *self.text then fail
  44.         rv := self.text[self.index]
  45.         self.index +:= 1
  46.         return rv
  47.       end
  48.       # place the buffer's text into a contiguously allocated list
  49.       method linearize()
  50.         tmp := list(*self.text)
  51.         every i := 1 to *tmp do tmp[i] := self.text[i]
  52.         self.text := tmp
  53.       end
  54.       method erase()
  55.         self.text     := [ ]
  56.         self.index    := 1
  57.       end
  58.     initially
  59.       if \ (self.filename) then {
  60.         if not self$read() then self$erase()
  61.       } else {
  62.         self.filename := "*scratch*"
  63.         self.erase()
  64.       }
  65.     end
  66.  
  67.  
  68. class buftable : buffer()
  69.   method read()
  70.     self$buffer.read()
  71.     tmp := table()
  72.     every line := !self.text do
  73.       line ? { tmp[tab(many(&ucase++&lcase))] := line | fail }
  74.     self.text := tmp
  75.     return
  76.   end
  77.   method lookup(s)
  78.     return self.text[s]
  79.   end
  80. end
  81.  
  82.  
  83. class bibliography : buftable()
  84. end
  85.  
  86.  
  87. class spellChecker : buftable(parentSpellChecker)
  88.   method spell(s)
  89.     return \ (self.text[s]) | (\ (self.parentSpellChecker))$spell(s)
  90.   end
  91. end
  92.  
  93.  
  94. class dictentry(word,pos,etymology,definition)
  95.   method decode(s) # decode a dictionary entry into its components
  96.     s ? {
  97.       self.word       := tab(upto(';'))
  98.       move(1)
  99.       self.pos        := tab(upto(';'))
  100.       move(1)
  101.       self.etymology  := tab(upto(';'))
  102.       move(1)
  103.       self.definition := tab(0)
  104.     }
  105.   end
  106.   method encode()  # encode a dictionary entry into a string
  107.     return self.word||";"||self.pos||";"||self.etymology||";"||self.definition
  108.   end
  109. initially
  110.   if /self.pos then {
  111.     # constructor was called with a single string argument
  112.     self$decode(self.word)
  113.   }
  114. end
  115.  
  116. class dictionary : buftable()
  117.   method read()
  118.     self$buffer.read()
  119.     tmp := table()
  120.     every line := !self.text do
  121.       line ? { tmp[tab(many(&ucase++&lcase))] := dictentry(line) | fail }
  122.     self.text := tmp
  123.   end
  124.   method write()
  125.     f := open(b.filename,"w") | fail
  126.     every write(f,(!self.text)$encode())
  127.     close(f)
  128.   end
  129. end
  130.